<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Equality constrained norm minimization.</title>
<link rel="canonical" href="/Users/mcgrant/Projects/CVX/examples/html/equality_constr_norm_min.html">
<link rel="stylesheet" href="../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Equality constrained norm minimization.</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% This script constructs a random equality-constrained norm minimization</span>
<span class="comment">% problem and solves it using CVX. You can also change p to +2 or +Inf</span>
<span class="comment">% to produce different results. Alternatively, you an replace</span>
<span class="comment">%     norm( A * x - b, p )</span>
<span class="comment">% with</span>
<span class="comment">%     norm_largest( A * x - b, 'largest', p )</span>
<span class="comment">% for 1 &lt;= p &lt;= 2 * n.</span>

<span class="comment">% Generate data</span>
p = 1;
n = 10; m = 2*n; q=0.5*n;
A = randn(m,n);
b = randn(m,1);
C = randn(q,n);
d = randn(q,1);

<span class="comment">% Create and solve problem</span>
cvx_begin
   variable <span class="string">x(n)</span>
   dual <span class="string">variable</span> <span class="string">y</span>
   minimize( norm( A * x - b, p ) )
   subject <span class="string">to</span>
        y : C * x == d;
cvx_end

<span class="comment">% Display results</span>
disp( sprintf( <span class="string">'norm(A*x-b,%g):'</span>, p ) );
disp( [ <span class="string">'   ans   =   '</span>, sprintf( <span class="string">'%7.4f'</span>, norm(A*x-b,p) ) ] );
disp( <span class="string">'Optimal vector:'</span> );
disp( [ <span class="string">'   x     = [ '</span>, sprintf( <span class="string">'%7.4f '</span>, x ), <span class="string">']'</span> ] );
disp( <span class="string">'Residual vector:'</span> );
disp( [ <span class="string">'   A*x-b = [ '</span>, sprintf( <span class="string">'%7.4f '</span>, A*x-b ), <span class="string">']'</span> ] );
disp( <span class="string">'Equality constraints:'</span> );
disp( [ <span class="string">'   C*x   = [ '</span>, sprintf( <span class="string">'%7.4f '</span>, C*x ), <span class="string">']'</span> ] );
disp( [ <span class="string">'   d     = [ '</span>, sprintf( <span class="string">'%7.4f '</span>, d   ), <span class="string">']'</span> ] );
disp( <span class="string">'Lagrange multiplier for C*x==d:'</span> );
disp( [ <span class="string">'   y     = [ '</span>, sprintf( <span class="string">'%7.4f '</span>, y ), <span class="string">']'</span> ] );
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Calling SDPT3 4.0: 50 variables, 25 equality constraints
------------------------------------------------------------

 num. of constraints = 25
 dim. of socp   var  = 40,   num. of socp blk  = 20
 dim. of free   var  = 10 *** convert ublk to lblk
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
    NT      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
 0|0.000|0.000|8.1e-01|2.8e+01|1.4e+04| 5.143640e+01  0.000000e+00| 0:0:00| chol  1  1 
 1|1.000|0.856|5.1e-06|4.1e+00|9.7e+02| 3.170797e+02  1.559244e+01| 0:0:00| chol  1  1 
 2|1.000|0.987|1.1e-06|6.3e-02|5.5e+01| 6.323422e+01  1.038030e+01| 0:0:00| chol  1  1 
 3|0.884|0.971|2.8e-06|2.7e-03|6.0e+00| 2.028692e+01  1.435501e+01| 0:0:00| chol  1  1 
 4|0.890|0.116|9.8e-06|3.3e-03|3.1e+00| 1.757201e+01  1.464034e+01| 0:0:00| chol  1  1 
 5|1.000|0.601|1.4e-06|1.3e-03|1.1e+00| 1.696414e+01  1.591961e+01| 0:0:00| chol  1  1 
 6|0.960|0.782|3.5e-07|2.9e-04|2.0e-01| 1.673312e+01  1.653658e+01| 0:0:00| chol  1  1 
 7|0.955|0.835|5.6e-08|4.8e-05|3.1e-02| 1.671466e+01  1.668403e+01| 0:0:00| chol  1  1 
 8|0.983|0.979|1.5e-08|1.0e-06|6.6e-04| 1.671341e+01  1.671276e+01| 0:0:00| chol  1  1 
 9|0.989|0.989|3.1e-09|4.5e-06|1.8e-05| 1.671339e+01  1.671338e+01| 0:0:00| chol  1  1 
10|1.000|0.989|1.8e-11|1.2e-07|4.3e-07| 1.671339e+01  1.671339e+01| 0:0:00| chol  1  1 
11|0.541|0.945|8.2e-12|2.9e-09|3.7e-08| 1.671339e+01  1.671339e+01| 0:0:00|
  stop: max(relative gap, infeasibilities) &lt; 1.49e-08
-------------------------------------------------------------------
 number of iterations   = 11
 primal objective value =  1.67133912e+01
 dual   objective value =  1.67133911e+01
 gap := trace(XZ)       = 3.74e-08
 relative gap           = 1.09e-09
 actual relative gap    = 8.80e-10
 rel. primal infeas (scaled problem)   = 8.21e-12
 rel. dual     "        "       "      = 2.91e-09
 rel. primal infeas (unscaled problem) = 0.00e+00
 rel. dual     "        "       "      = 0.00e+00
 norm(X), norm(y), norm(Z) = 7.0e+00, 1.0e+01, 6.0e+00
 norm(A), norm(b), norm(C) = 2.3e+01, 5.2e+00, 5.5e+00
 Total CPU time (secs)  = 0.28  
 CPU time per iteration = 0.03  
 termination code       =  0
 DIMACS: 1.5e-11  0.0e+00  8.0e-09  0.0e+00  8.8e-10  1.1e-09
-------------------------------------------------------------------
 
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +16.7134
 
norm(A*x-b,1):
   ans   =   16.7134
Optimal vector:
   x     = [  0.0026 -0.1810 -0.4690 -0.1179 -0.0525  0.0758  0.0980  0.1892 -0.1700  0.4621 ]
Residual vector:
   A*x-b = [  0.0000 -2.0940  0.6100 -0.8864 -1.8009  0.0000 -0.9764 -0.7311  1.5586  1.1282 -1.4916 -0.0069 -0.0000 -0.0000 -1.5960  0.0629  0.5158  0.0000 -1.8174  1.4373 ]
Equality constraints:
   C*x   = [  0.1555  0.8186 -0.2926 -0.5408 -0.3086 ]
   d     = [  0.1555  0.8186 -0.2926 -0.5408 -0.3086 ]
Lagrange multiplier for C*x==d:
   y     = [ -6.7354  1.6456 -2.1811 -6.2263  0.4799 ]
</pre>
</div>
</body>
</html>